home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / findisk3 / part03 < prev   
Text File  |  1991-11-20  |  49KB  |  2,554 lines

  1. Path: news.larc.nasa.gov!amiga-request
  2. From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v91i201: FindDisk 3.3 - disk catalogger utility, Part03/03
  4. Reply-To: Ross MacGregor <haley@unixg.ubc.ca>
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga.v91i201@ab20.larc.nasa.gov>
  7. References: <comp.sources.amiga.v91i199@ab20.larc.nasa.gov>
  8. Date: 20 Nov 91 11:10:59 GMT
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga.misc
  12.  
  13. Submitted-by: Ross MacGregor <haley@unixg.ubc.ca>
  14. Posting-number: Volume 91, Issue 201
  15. Archive-name: utilities/finddisk-3.3/part03
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 3)."
  24. # Contents:  fd2src/fd2.c fd3src/fd3.c
  25. # Wrapped by tadguy@ab20 on Tue Nov 19 21:17:43 1991
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'fd2src/fd2.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'fd2src/fd2.c'\"
  29. else
  30. echo shar: Extracting \"'fd2src/fd2.c'\" \(21252 characters\)
  31. sed "s/^X//" >'fd2src/fd2.c' <<'END_OF_FILE'
  32. X
  33. X/*                            FindDisk2.3
  34. X
  35. X     Author      : Ross MacGregor
  36. X     Date        : 27/10/88
  37. X     Last Update : 23 Apr 91
  38. X     Comments    : This is a public domain program.
  39. X
  40. X
  41. X     DiskList storein compacted form:
  42. X
  43. X     below: { unskrunched } => { skrunched }
  44. X            [] is a byte of memory
  45. X
  46. X     * compacts strings of spaces
  47. X         { [$20] [$20] [$20] [$20] [$20] } => { [SKRUNCHAR] [SKRUNOFFS 5] }
  48. X         { [$20] [$20] } => { [$20] [$20] }
  49. X
  50. X     * the STARTSTR is compacted
  51. X         { STARTSTR } => { [STARTCHAR] }
  52. X
  53. X*/
  54. X
  55. X#include <functions.h>
  56. X#include <string.h>
  57. X
  58. X#include <exec/types.h>
  59. X#include <exec/nodes.h>
  60. X#include <exec/lists.h>
  61. X#include <exec/libraries.h>
  62. X#include <exec/ports.h>
  63. X#include <exec/interrupts.h>
  64. X#include <exec/io.h>
  65. X#include <exec/memory.h>
  66. X#include <libraries/dos.h>
  67. X#include <libraries/dosextens.h>
  68. X
  69. X
  70. X/* lattice may want smaller strings */
  71. X
  72. X#define HELPTEXT1  "\nFindDisk2.3:\n\
  73. XFD -l             ; Loads DiskList to ram:\n\
  74. XFD -s             ; Saves DiskList back to disk (first doing an update)\n\
  75. XFD -d  [path]     ; Saves dir listing to ram:TempDL\n\
  76. XFD -a  [path]     ; Saves listing with all sub-directories included\n\
  77. XFD -u             ; Updates the DiskList with TempDL\n\
  78. XFD -n             ; Creates a new (empty) DiskList\n"
  79. X
  80. X#define HELPTEXT2  "FD -r  diskname   ; Removes directory from DiskList matching 'diskname'\n\
  81. XFD text1 [textn]  ; Lists disk dir with a line containing text1 to textn\n\
  82. X  FD text           ; Case insensitive scan for text\n\
  83. X  FD !text          ; Case sensitive scan for for text\n"
  84. X
  85. X#define HELPTEXT3 "\nEnvironment Variables: (= default setting)\n\
  86. X  DLDISK  =  FindDisk:Disklist (Disk storage location/name)\n\
  87. X  DLTEMP  =  ram:DiskList (Ram storage location/name)\n\
  88. X  DLDRIVE =  df0: (Captures dir of this drive)\n\n"
  89. X
  90. X
  91. X#define CP_BUFF 10000L    /* Buffer size for the file copy function */
  92. X
  93. X
  94. X/* This indicates the start line of a dir listing, and
  95. X   it MUST have the name of the disk on the same line.  */
  96. X
  97. X#define STARTSTR  "Directory of "
  98. X
  99. X
  100. X/* Special character used to compact the spaces in DiskList */
  101. X#define SKRUNCHAR 1
  102. X#define SKRUNOFFS 10
  103. X
  104. X/* Special characters used to replace the STARTSTR */
  105. X#define STARTCHAR  2
  106. X
  107. X/* Lines in the stored dir listing array */
  108. X#define NUMLINES 25
  109. X
  110. X/* Max length of the lines read in */
  111. X#define LINELEN  170L
  112. X#define MAXBUF   169L
  113. X
  114. XBPTR fdl, ftmp;
  115. XBPTR confh;
  116. X
  117. Xchar *tempdl="ram:TempDL";
  118. X
  119. Xchar *dltemp="ram:DiskList", *dldisk="FindDisk:DiskList";
  120. Xchar *sdir_pat="df0:";
  121. X
  122. X#define MAXPATHLEN 80
  123. X
  124. Xchar *dlpath;
  125. Xchar buffer[LINELEN];
  126. X
  127. X/* global main arguments */
  128. Xint glargc;
  129. Xchar **glargv;
  130. X
  131. X/* function error indicator */
  132. Xint fcnerr;
  133. X
  134. Xchar *outofmem="Out of Memory Error.\n";
  135. Xchar *cutoff=" - - (no more lines available) - -\n";
  136. X
  137. X/* finddisk uses this */
  138. Xchar dirlist[NUMLINES][LINELEN];
  139. X
  140. X
  141. X/*------------ dynamic structure for coping DL to memory -------------*/
  142. X
  143. X/* Blocks of memory for storing the disklist */
  144. X#define BLKSIZE 4096L
  145. X
  146. Xstruct mem_block
  147. X{
  148. X  char buffer[BLKSIZE+1];
  149. X  struct mem_block *next;
  150. X};
  151. X
  152. Xstruct mem_block *mem_blocks, *cur_mem_block;
  153. Xchar *mem_block_ptr;
  154. Xint chrcount;
  155. Xvoid init_bufblks(), free_bufblks();
  156. Xint  write_bufblks(BPTR fd);
  157. X
  158. X/*------------ dynamic structure for listing the volume names --------*/
  159. X/*                   used in recursive do_ls call also                */
  160. X
  161. Xstruct disk
  162. X{
  163. X  char name[LINELEN];
  164. X  struct disk *next;
  165. X};
  166. Xstruct disk *firstdisk,*diskptr;
  167. X
  168. X#define INIT_DISKNAMES firstdisk=diskptr=NULL
  169. X#define FREE_DISKNAMES free_disknames()
  170. X
  171. Xvoid free_disknames();
  172. X
  173. X/*----------------------------------------------------------------------*/
  174. X
  175. Xchar *mystrstr(), *strtoupper(), *getstr();
  176. Xvoid putstr();
  177. X
  178. Xchar *skrunch(), *getenv();
  179. Xvoid unskrunch(), get_dlpath();
  180. X
  181. XBPTR opendl(), opentmp();
  182. Xchar *getenv();
  183. Xvoid get_dlpath();
  184. X
  185. Xvoid finddisk();
  186. Xvoid print_dir_if(int thisone,int line);
  187. X
  188. Xint update(), remove(), loaddl(), savedl(), sdir(), newdl();
  189. X
  190. Xvoid update_free(), ls_free(), remove_free();
  191. X
  192. Xchar *strchr(), *malloc();
  193. X
  194. Xvoid main(argc,argv)
  195. X  int argc;
  196. X  char *argv[];
  197. X{
  198. X
  199. X  glargv=argv;
  200. X  glargc=argc;
  201. X
  202. X  if( (confh=Output())==NULL )
  203. X    exit(1);
  204. X
  205. X  if( argc==1)
  206. X  {
  207. X    putstr(HELPTEXT1);
  208. X    putstr(HELPTEXT2);
  209. X    putstr(HELPTEXT3);
  210. X    exit(0);
  211. X  }
  212. X
  213. X  dldisk=getenv("env:dldisk",dldisk);
  214. X  dltemp=getenv("env:dltemp",dltemp);
  215. X  sdir_pat=getenv("env:dldrive",sdir_pat);
  216. X  get_dlpath();
  217. X
  218. X  if( *argv[1]=='-' )
  219. X  {
  220. X    switch( *(argv[1]+1) )
  221. X    {
  222. X       case 'd':  if( sdir(0) )
  223. X                    putstr("SaveDir failed!\n");
  224. X                  break;
  225. X
  226. X       case 'a':  if( sdir(1) )
  227. X                    putstr("SaveDir failed!\n");
  228. X                  break;
  229. X
  230. X       case 's':  if( savedl() )
  231. X                    putstr("SaveDL failed!\n");
  232. X                  break;
  233. X
  234. X       case 'l':  if( loaddl() )
  235. X                    putstr("LoadDL failed!\n");
  236. X                  break;
  237. X
  238. X       case 'u':  if( update() )
  239. X                    putstr("Update failed!\n");
  240. X                  break;
  241. X
  242. X       case 'r':  if( remove() )
  243. X                    putstr("Remove failed!\n");
  244. X                  break;
  245. X
  246. X       case 'n':  if( newdl() )
  247. X                    putstr("Empty DiskList created (Save if in RAM).\n");
  248. X                  break;
  249. X
  250. X       default :  putstr("Unknown Option.\n");
  251. X    }
  252. X  }
  253. X  else finddisk();
  254. X
  255. X}
  256. X
  257. X
  258. Xchar *getenv(fullpath,var)
  259. X  char *fullpath, *var;
  260. X{
  261. X  BPTR lock;
  262. X  BPTR fh;
  263. X  char *buffer;
  264. X  int  len;
  265. X
  266. X  if( lock=Lock(fullpath,(long)ACCESS_READ) )
  267. X  {
  268. X    UnLock(lock);
  269. X    if( !(fh=Open(fullpath,(long)MODE_OLDFILE)) )
  270. X      return var;
  271. X    if( !(buffer=(char *)malloc(MAXPATHLEN+1)) )
  272. X    {
  273. X      putstr(outofmem);
  274. X      Close(fh);
  275. X      return var;
  276. X    }
  277. X    len=Read(fh,buffer,(long)MAXPATHLEN);
  278. X    Close(fh);
  279. X    *(buffer+len)='\0';
  280. X    return buffer;
  281. X  }
  282. X  return var;
  283. X}
  284. X
  285. X
  286. Xvoid finddisk()
  287. X{
  288. X  int  kase=0, thisone=0, line=0;
  289. X  int i;
  290. X  char *p;
  291. X
  292. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  293. X    return;
  294. X
  295. X  /* Converts non-case sensitive keywords to upper case */
  296. X  for(i=1; i<glargc; i++)
  297. X    if( *glargv[i]!='!' )
  298. X      strtoupper(glargv[i]);
  299. X
  300. X  /* get line of DiskList */
  301. X  while( getstr(buffer,fdl) !=NULL )
  302. X  {
  303. X
  304. X    /* first checks for a startchar of a dirlist */
  305. X    if( strchr(buffer,(char)STARTCHAR) )
  306. X    {
  307. X       print_dir_if(thisone,line);
  308. X       thisone=0;
  309. X       line=1;
  310. X    }
  311. X
  312. X    if( line )
  313. X    {
  314. X       /* Copies the line in buffer to the stored dirlist */
  315. X       strcpy(dirlist[line-1],buffer);
  316. X
  317. X       if( ++line > NUMLINES )
  318. X         line--;
  319. X
  320. X       /* Checks for given keywords */
  321. X       if( thisone==0 )
  322. X         for(i=1; i<glargc; i++)
  323. X         {
  324. X           if( *glargv[i]=='!' )
  325. X           {
  326. X             p=glargv[i]+1;
  327. X             kase=1;
  328. X           }
  329. X           else
  330. X           {
  331. X             p=glargv[i];
  332. X             kase=0;
  333. X           }
  334. X
  335. X           if( mystrstr(buffer,p,kase) )
  336. X             thisone=1;
  337. X           else
  338. X           {
  339. X             thisone=0;
  340. X             break;
  341. X           }
  342. X         }
  343. X
  344. X    }/* if(line) */
  345. X
  346. X  } /* while( get next buffer) */
  347. X
  348. X  print_dir_if(thisone,line);
  349. X
  350. X  Close(fdl);
  351. X}
  352. X
  353. Xvoid print_dir_if(int thisone,int line)
  354. X{
  355. X  int i;
  356. X
  357. X  if( thisone )
  358. X  {
  359. X        line--;
  360. X        for(i=0; i<line; i++)
  361. X          unskrunch(dirlist[i]);
  362. X
  363. X        /* if at the end of the dirlist array- prints 'cut off' */
  364. X        if( line==NUMLINES-1 )
  365. X          putstr(cutoff);
  366. X  }
  367. X}
  368. X
  369. X
  370. X
  371. X#define update_cleanup(x)  { update_free(); return x; }
  372. X
  373. Xupdate()
  374. X{
  375. X  int  i;
  376. X
  377. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  378. X    return 1;
  379. X
  380. X  if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
  381. X  {
  382. X    Close(fdl);
  383. X    return 0;
  384. X  }
  385. X
  386. X  INIT_DISKNAMES;
  387. X  init_bufblks();
  388. X
  389. X  /* finds the disks names in TempDL */
  390. X  while( getstr(buffer,ftmp) !=NULL )
  391. X  {
  392. X      if( mystrstr(buffer,STARTSTR,1) )
  393. X      {
  394. X         skrunch(buffer);
  395. X         if( storename(buffer) )
  396. X           update_cleanup(3)
  397. X      }
  398. X  }
  399. X  if( fcnerr )
  400. X    update_cleanup(10)
  401. X
  402. X  if( storedl() )
  403. X    update_cleanup(4)
  404. X
  405. X  Seek(ftmp,0L,(long)OFFSET_BEGINNING);
  406. X
  407. X  /* store TempDL in memory */
  408. X  while( getstr(buffer,ftmp) !=NULL )
  409. X    if( store( skrunch(buffer) ) )
  410. X      update_cleanup(5)
  411. X  if( fcnerr )
  412. X    update_cleanup(6);
  413. X
  414. X  Close(fdl);
  415. X  if( !(fdl=opendl((long)MODE_NEWFILE)) )
  416. X  {
  417. X    Close(ftmp);
  418. X    FREE_DISKNAMES;
  419. X    free_bufblks();
  420. X    return 7;
  421. X  }
  422. X
  423. X  /* write the in memory disklist to the one in ram: */
  424. X    if( write_bufblks(fdl) )
  425. X      update_cleanup(8)
  426. X
  427. X  Close(ftmp);
  428. X  if( !(ftmp=opentmp((long)MODE_NEWFILE)) )
  429. X    update_cleanup(9)
  430. X
  431. X  update_free();
  432. X  return 0;
  433. X}
  434. X
  435. Xvoid update_free()
  436. X{
  437. X  Close(fdl);
  438. X  Close(ftmp);
  439. X  FREE_DISKNAMES;
  440. X  free_bufblks();
  441. X}
  442. X
  443. X
  444. X
  445. X
  446. X#define remove_cleanup(x)  { remove_free(); return x; }
  447. X
  448. Xremove()
  449. X{
  450. X  int i;
  451. X
  452. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  453. X    return 2;
  454. X
  455. X  INIT_DISKNAMES;
  456. X  init_bufblks();
  457. X
  458. X  /* finds the disk name in DiskList */
  459. X  while( getstr(buffer,fdl) !=NULL )
  460. X  {
  461. X      if( mystrstr(buffer,glargv[2],1) )
  462. X      {
  463. X         if( storename(buffer) )
  464. X           remove_cleanup(3)
  465. X      }
  466. X  }
  467. X  if( fcnerr )
  468. X    remove_cleanup(4);
  469. X
  470. X  Seek(fdl,0L,(long)OFFSET_BEGINNING);
  471. X
  472. X  if( storedl() )
  473. X    remove_cleanup(5)
  474. X
  475. X  Close(fdl);
  476. X  if( !(fdl=opendl((long)MODE_NEWFILE)) )
  477. X  {
  478. X    FREE_DISKNAMES;
  479. X    free_bufblks();
  480. X    return 6;
  481. X  }
  482. X
  483. X  /* write the in memory disklist to the one in ram: */
  484. X  if( write_bufblks(fdl) )
  485. X      remove_cleanup(7)
  486. X
  487. X  remove_free();
  488. X  return 0;
  489. X}
  490. X
  491. X
  492. Xvoid remove_free()
  493. X{
  494. X  Close(fdl);
  495. X  FREE_DISKNAMES;
  496. X  free_bufblks();
  497. X}
  498. X
  499. X
  500. X
  501. X/* loads the DiskList into memory but leaves out the directories in the
  502. X   diskname list, pointed to by firstdisk */
  503. Xstoredl()
  504. X{
  505. X  int storeit=1;  /* saving this directory */
  506. X
  507. X  /* doesn't store directories that are in the temp file */
  508. X  while( getstr(buffer,fdl) !=NULL )
  509. X  {
  510. X      if( strchr(buffer,(char)STARTCHAR) )
  511. X      {
  512. X         storeit=1;
  513. X         diskptr=firstdisk;
  514. X         while(diskptr)
  515. X         {
  516. X           if( mystrstr(buffer,diskptr->name,1) )
  517. X           {
  518. X             storeit=0;
  519. X             break;
  520. X           }
  521. X           diskptr=diskptr->next;
  522. X         }
  523. X      }
  524. X
  525. X      if(storeit)
  526. X       if( store(buffer) )
  527. X         return 1;
  528. X  }
  529. X
  530. X  return fcnerr;
  531. X}
  532. X
  533. X
  534. X
  535. X/* Saves the name of a disk in a linked list structure */
  536. Xstorename(buffer)
  537. X char *buffer;
  538. X{
  539. X  if( diskptr==NULL )
  540. X  {
  541. X    if( (firstdisk=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
  542. X    {
  543. X      putstr(outofmem);
  544. X      return 1;
  545. X    }
  546. X    diskptr=firstdisk;
  547. X    strcpy(diskptr->name,buffer);
  548. X    diskptr->next=NULL;
  549. X  }
  550. X  else
  551. X  {
  552. X    if( (diskptr->next=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
  553. X    {
  554. X      putstr(outofmem);
  555. X      return 2;
  556. X    }
  557. X    diskptr=diskptr->next;
  558. X    strcpy(diskptr->name,buffer);
  559. X    diskptr->next=NULL;
  560. X  }
  561. X
  562. X  return 0;
  563. X}
  564. X
  565. Xvoid free_disknames()
  566. X{
  567. X  struct disk *p;
  568. X
  569. X  while(firstdisk)
  570. X  {
  571. X    p=firstdisk->next;
  572. X    free(firstdisk);
  573. X    firstdisk=p;
  574. X  }
  575. X}
  576. X
  577. X
  578. X/* prints line to stdout unskrunched */
  579. X/* format  [BYTE]=>   [SKRUNCHAR] [# of spaces ]   */
  580. X
  581. Xvoid unskrunch(line)
  582. X  char *line;
  583. X{
  584. X  char output[LINELEN], *p;
  585. X  int i;
  586. X
  587. X  p=output;
  588. X  while(*line)
  589. X  {
  590. X    switch((int)*line)
  591. X    {
  592. X      case SKRUNCHAR : line++;
  593. X                       for(i=SKRUNOFFS; i<(int)*line; i++)
  594. X                         *(p++)=' ';
  595. X                       break;
  596. X
  597. X      case STARTCHAR : strcpy(p,STARTSTR);
  598. X                       p+=strlen(STARTSTR);
  599. X                       break;
  600. X
  601. X      default : *(p++)=*line;
  602. X    }
  603. X
  604. X    line++;
  605. X  }
  606. X  *p='\0';
  607. X  putstr(output);
  608. X}
  609. X
  610. X
  611. Xchar *skrunch(line)
  612. X  char *line;
  613. X{
  614. X  char skbuf[LINELEN],*p;
  615. X  int  spaces=0;
  616. X
  617. X  /* first tokenizes the STARTSTR/XnSTR if in line */
  618. X
  619. X  tokenize(line,STARTSTR,STARTCHAR);
  620. X
  621. X  /* this is the compaction of >2 spaces */
  622. X  p=skbuf;
  623. X  while( *line )
  624. X  {
  625. X    if( *line==' ' )
  626. X      spaces++;
  627. X    else
  628. X    {
  629. X      if( spaces )
  630. X        if( spaces>2 )
  631. X        {
  632. X          *(p++)=(char)SKRUNCHAR;
  633. X          *(p++)=(char)(spaces+SKRUNOFFS);
  634. X          spaces=0;
  635. X        }
  636. X        else
  637. X        {
  638. X          *(p++)=' ';
  639. X          if( spaces>1 ) *(p++)=' ';
  640. X          spaces=0;
  641. X        }
  642. X
  643. X      *p=*line;
  644. X      p++;
  645. X    }
  646. X    line++;
  647. X  }
  648. X  *p='\0';
  649. X  strcpy(buffer,skbuf);
  650. X  return buffer;
  651. X}
  652. X
  653. X
  654. X/* will tokenize first occurance of STR in LINE */
  655. Xtokenize(line,str,chr)
  656. X  char *line,*str;
  657. X  int  chr;
  658. X{
  659. X  char *p,*q;
  660. X
  661. X  if( p=mystrstr(line,str,1) )
  662. X  {
  663. X    q=p+strlen(str);
  664. X    *p=(char)chr;
  665. X    strcpy(p+1,q);
  666. X    return 1;
  667. X  }
  668. X  return 0;
  669. X}
  670. X
  671. X
  672. X
  673. X/* stores line to memory */
  674. Xstore(buffer)
  675. X  char *buffer;
  676. X{
  677. X  struct mem_block *p;
  678. X  int i;
  679. X
  680. X  i=strlen(buffer);
  681. X  chrcount+=i;
  682. X
  683. X  if( chrcount>=BLKSIZE )
  684. X  {
  685. X    if( mem_block_ptr )
  686. X      *mem_block_ptr='\0';
  687. X    chrcount=i;
  688. X
  689. X    if( (p=(struct mem_block *)malloc(sizeof(struct mem_block)) )==NULL)
  690. X    {
  691. X       putstr(outofmem);
  692. X       return 2;
  693. X    }
  694. X
  695. X    p->next=NULL;
  696. X
  697. X    if( mem_blocks )
  698. X      cur_mem_block->next=p;
  699. X    else
  700. X      mem_blocks=p;
  701. X    cur_mem_block=p;
  702. X
  703. X    mem_block_ptr=cur_mem_block->buffer;
  704. X  }
  705. X
  706. X  strcpy(mem_block_ptr,buffer);
  707. X  mem_block_ptr+=i;
  708. X
  709. X  return 0;
  710. X}
  711. X
  712. Xwrite_bufblks(BPTR fd)
  713. X{
  714. X  struct mem_block *p;
  715. X
  716. X  p=mem_blocks;
  717. X  while(p)
  718. X  {
  719. X    if( fputstr(p->buffer,fd) )
  720. X      return 1;
  721. X    p=p->next;
  722. X  }
  723. X
  724. X  return 0;
  725. X}
  726. X
  727. X
  728. Xvoid init_bufblks()
  729. X{
  730. X  mem_block_ptr=NULL;
  731. X  chrcount=BLKSIZE+1;
  732. X  cur_mem_block=NULL;
  733. X  mem_blocks=NULL;
  734. X}
  735. X
  736. Xvoid free_bufblks()
  737. X{
  738. X  struct mem_block *p,*next;
  739. X
  740. X  p=mem_blocks;
  741. X  while(p)
  742. X  {
  743. X    next=p->next;
  744. X    free(p);
  745. X    p=next;
  746. X  }
  747. X}
  748. X
  749. X
  750. X/*   OK, this is not quite a true strstr() with case switch.
  751. X     The sub string must be in upper case if kase=0 (?!sorry)    */
  752. X
  753. Xchar *mystrstr(str,sub,kase)
  754. X  char *str,*sub;
  755. X  int  kase;
  756. X{
  757. X  int length;
  758. X
  759. X  length=strlen(sub);
  760. X
  761. X  if( kase )
  762. X    str=strchr(str,*sub);
  763. X  else
  764. X    str=strchr(strtoupper(str),*sub);
  765. X
  766. X  while( str )
  767. X  {
  768. X    if( strncmp(str,sub,length) )
  769. X      str++;
  770. X    else
  771. X      return str;
  772. X
  773. X    str=strchr(str,*sub);
  774. X  }
  775. X
  776. X  return NULL;
  777. X}
  778. X
  779. Xchar *strtoupper(s)
  780. X  char *s;
  781. X{
  782. X    register char *p = s;
  783. X
  784. X    while(*p)
  785. X    {
  786. X       *p = toupper(*p);
  787. X       p++;
  788. X    }
  789. X    return(s);
  790. X}
  791. X
  792. Xvoid get_dlpath()
  793. X{
  794. X  BPTR lock;
  795. X
  796. X  if( lock=Lock(dltemp,(long)ACCESS_READ) )
  797. X  {
  798. X    dlpath=dltemp;
  799. X    UnLock(lock);
  800. X  }
  801. X  else
  802. X    dlpath=dldisk;
  803. X}
  804. X
  805. XBPTR opendl(mode)
  806. X  long mode;
  807. X{
  808. X  BPTR fdl;
  809. X
  810. X  if( (fdl=Open(dlpath,mode))==NULL)
  811. X  {
  812. X    putstr("Error: Could not open DiskList\n");
  813. X    return 0;
  814. X  }
  815. X  return fdl;
  816. X}
  817. X
  818. X
  819. X#define MODE_APPEND 1000L
  820. X
  821. XBPTR opentmp(mode)
  822. X  long mode;
  823. X{
  824. X  BPTR ftmp;
  825. X  BPTR lock;
  826. X  int    seek=0;
  827. X
  828. X  if( mode==MODE_APPEND)
  829. X  {
  830. X    if( lock=Lock(tempdl,(long)ACCESS_READ) )
  831. X    {
  832. X      UnLock(lock);
  833. X      mode=(long)MODE_OLDFILE;
  834. X      seek=1;
  835. X    }
  836. X    else
  837. X      mode=(long)MODE_NEWFILE;
  838. X  }
  839. X
  840. X  if( (ftmp=Open(tempdl,mode))==NULL)
  841. X  {
  842. X    putstr("Error: Could not open RAM:TempDL\n");
  843. X    return 0;
  844. X  }
  845. X
  846. X  if( seek )
  847. X    Seek(ftmp,0L,(long)OFFSET_END);
  848. X
  849. X  return ftmp;
  850. X}
  851. X
  852. X
  853. Xsdir(recur)
  854. X  int recur;
  855. X{
  856. X  char *p;
  857. X
  858. X
  859. X  if( glargc>2 )
  860. X    p=glargv[2];
  861. X  else
  862. X    p=sdir_pat;
  863. X
  864. X  if( !(ftmp=opentmp(MODE_APPEND)) )
  865. X    return 1;
  866. X
  867. X  if( do_ls(p,ftmp,recur) )
  868. X  {
  869. X    Close(ftmp);
  870. X    return 2;
  871. X  }
  872. X  Close(ftmp);
  873. X  return 0;
  874. X}
  875. X
  876. X
  877. X#define ls_cleanup(x) { ls_free(lock,f_info); return x; }
  878. X
  879. Xdo_ls(pat,fh,recur)
  880. X  char *pat;
  881. X  BPTR fh;
  882. X  int recur;
  883. X{
  884. X  BPTR lock=NULL;
  885. X  struct FileInfoBlock *f_info;
  886. X
  887. X  char *s, *tempstr;
  888. X  int  slen, isadir, col, patchg=0, firstrun=1;
  889. X  char *spaces1, *spaces2;
  890. X  struct disk *nextdir;
  891. X  char basename[80], tempname[80];
  892. X
  893. X
  894. X  /* strings of 18 & 36 spaces for formatting output */
  895. X  /*       012345678901234567                        */
  896. X  spaces1="                  ";
  897. X  /*       0123456789012345678901234567890123456     */
  898. X  spaces2="                                     ";
  899. X
  900. X  INIT_DISKNAMES;
  901. X  nextdir=NULL;
  902. X
  903. X  strcpy(tempname,"/");
  904. X  tempstr=tempname+1;
  905. X
  906. X  if((f_info=(struct FileInfoBlock *)
  907. X     AllocMem((long)sizeof(struct FileInfoBlock),0L))==0)
  908. X  {
  909. X    putstr(outofmem);
  910. X    FREE_DISKNAMES;
  911. X    return 1;
  912. X  }
  913. X
  914. X  do
  915. X  {
  916. X    if( firstdisk )
  917. X    {
  918. X      while( nextdir && *(nextdir->name)=='/' )
  919. X      {
  920. X        strncpy(basename,(nextdir->name)+1,78);
  921. X        strncpy(basename+strlen(basename),"/",2);
  922. X        nextdir=nextdir->next;
  923. X        if( !nextdir )
  924. X          ls_cleanup(0)
  925. X      }
  926. X      strncpy(tempname+1,basename,78);
  927. X      slen=strlen(tempname);
  928. X      strncpy(tempname+slen,nextdir->name,79-slen);
  929. X      if( storename(tempname) )
  930. X        ls_cleanup(1);
  931. X      pat=tempname+1;
  932. X    }
  933. X
  934. X    do
  935. X    {
  936. X      if( firstrun )
  937. X      {
  938. X        if(patchg==1)
  939. X        {
  940. X          patchg=2;
  941. X          strncpy(tempstr,f_info->fib_FileName,78);
  942. X          slen=strlen(tempstr);
  943. X          tempstr[slen]=':';
  944. X          strncpy(tempstr+slen+1,s+4,78-slen);
  945. X          pat=tempstr;
  946. X        }
  947. X        else if( strchr(pat,':')<strchr(pat,'\0')-1 )
  948. X        {
  949. X          patchg=2;
  950. X          if( !(strncmp(pat,"df0:",4) && strncmp(pat,"df1:",4)) )
  951. X          {
  952. X            patchg=1;
  953. X            strncpy(tempstr,pat,4);
  954. X            *(tempstr+4)='\0';
  955. X            s=pat;
  956. X            pat=tempstr;
  957. X          }
  958. X        }
  959. X      }
  960. X
  961. X      if((lock=Lock(pat,(long)ACCESS_READ))==0)
  962. X        ls_cleanup(2)
  963. X
  964. X      if((Examine(lock,f_info))==0)
  965. X        ls_cleanup(3)
  966. X    }
  967. X    while( patchg==1 );
  968. X    firstrun=0;
  969. X
  970. X    if( fputstr(STARTSTR,fh) )
  971. X      ls_cleanup(4)
  972. X    if( firstdisk )
  973. X    {
  974. X      fputstr(tempname+1,fh);
  975. X      fputstr ("\n",fh);
  976. X    }
  977. X    else
  978. X    {
  979. X      if( patchg )
  980. X      {
  981. X        patchg=0;
  982. X        if( fputstr(pat,fh) )
  983. X          ls_cleanup(5)
  984. X        fputstr ("\n",fh);
  985. X        strncpy(basename,pat,79L);
  986. X        slen=strlen(basename);
  987. X        basename[slen++]='/';
  988. X        basename[slen]='\0';
  989. X
  990. X      }
  991. X      else
  992. X      {
  993. X        if( fputstr(f_info->fib_FileName,fh) )
  994. X          ls_cleanup(6)
  995. X        fputstr (":\n",fh);
  996. X        strncpy(basename,f_info->fib_FileName,78);
  997. X        slen=strlen(basename);
  998. X        basename[slen++]=':';
  999. X        basename[slen]='\0';
  1000. X      }
  1001. X    }
  1002. X    col=0;
  1003. X
  1004. X    while( (ExNext(lock,f_info))!=0)
  1005. X    {
  1006. X      s=f_info->fib_FileName;
  1007. X      slen=strlen(s);
  1008. X      isadir= (f_info->fib_DirEntryType>0);
  1009. X
  1010. X      if((col == 3) && slen >18) {
  1011. X           fputstr("\n",fh);
  1012. X           col = 0;
  1013. X      }
  1014. X
  1015. X      if (isadir)
  1016. X        fputstr ("\033[33m ",fh);
  1017. X      else
  1018. X        fputstr (" ",fh);
  1019. X
  1020. X      if (slen >18) {
  1021. X         if( fputstr(s,fh) )
  1022. X           ls_cleanup(7)
  1023. X         col += 2;
  1024. X         if( fputstr(spaces2+slen,fh) )
  1025. X           ls_cleanup(8)
  1026. X      }
  1027. X      else {
  1028. X         if( fputstr(s,fh) )
  1029. X           ls_cleanup(9)
  1030. X         if( fputstr(spaces1+slen,fh) )
  1031. X           ls_cleanup(10)
  1032. X         col++;
  1033. X      }
  1034. X
  1035. X      if( isadir && recur )
  1036. X        if(storename(s))
  1037. X          ls_cleanup(1);
  1038. X
  1039. X      if (isadir)
  1040. X        fputstr("\033[0m",fh);
  1041. X
  1042. X      if (col > 3) {
  1043. X         fputstr("\n",fh);
  1044. X         col = 0;
  1045. X      }
  1046. X
  1047. X    }
  1048. X    fputstr("\n",fh);
  1049. X    if( col )
  1050. X      fputstr("\n",fh);
  1051. X
  1052. X    UnLock(lock);
  1053. X    lock=NULL;
  1054. X
  1055. X    if( nextdir )
  1056. X      nextdir=nextdir->next;
  1057. X    else
  1058. X      nextdir=firstdisk;
  1059. X  }
  1060. X  while( nextdir );
  1061. X
  1062. X  ls_free(lock,f_info);
  1063. X  return 0;
  1064. X}
  1065. X
  1066. Xvoid ls_free(lock,f_info)
  1067. X  BPTR lock;
  1068. X  struct FileInfoBlock *f_info;
  1069. X
  1070. X{
  1071. X  if( lock )
  1072. X    UnLock(lock);
  1073. X  FreeMem(f_info,(long)sizeof(struct FileInfoBlock));
  1074. X  FREE_DISKNAMES;
  1075. X}
  1076. X
  1077. Xvoid putstr(str)
  1078. X  char *str;
  1079. X{
  1080. X    Write(confh,str,(long)strlen(str));
  1081. X}
  1082. X
  1083. X
  1084. Xfputstr(str,fh)
  1085. X  char *str;
  1086. X  BPTR fh;
  1087. X{
  1088. X   long len;
  1089. X   len=(long)strlen(str);
  1090. X   if( Write(fh,str,len)==len)
  1091. X     return 0;
  1092. X   return 1;
  1093. X}
  1094. X
  1095. X/* must be used in the WHILE( GETSTR()!=NULL) fashion */
  1096. Xchar *getstr(line,f)
  1097. X  char *line;
  1098. X  BPTR f;
  1099. X{
  1100. X  static char *buffer, *bufptr;
  1101. X  static int  last_read;
  1102. X  int len, n=MAXBUF;
  1103. X  char temp, *p, empty='\0';
  1104. X
  1105. X  if( !buffer )
  1106. X  {
  1107. X    if( (buffer=(char *)AllocMem((long)CP_BUFF+1,0L))==0)
  1108. X    {
  1109. X       putstr(outofmem);
  1110. X       fcnerr=1;
  1111. X       return (char *)0;
  1112. X    }
  1113. X    bufptr=∅
  1114. X  }
  1115. X
  1116. X  while(1)
  1117. X    if( p=strchr(bufptr,'\n') )
  1118. X    {
  1119. X      temp=*(++p);
  1120. X      *p='\0';
  1121. X      strncpy(line,bufptr,n);
  1122. X      *p=temp;
  1123. X      bufptr=p;
  1124. X      return line;
  1125. X    }
  1126. X    else
  1127. X    {
  1128. X      strncpy(line,bufptr,n);
  1129. X      len=strlen(line);
  1130. X      n-=len;
  1131. X      line+=len;
  1132. X
  1133. X      if( last_read )
  1134. X      {
  1135. X        FreeMem(buffer,CP_BUFF+1);
  1136. X        buffer=0;
  1137. X        last_read=0;
  1138. X        return (char *)0;
  1139. X      }
  1140. X      else
  1141. X        if( (len=Read(f,buffer,CP_BUFF)) <1 )
  1142. X          last_read=1;
  1143. X        else
  1144. X        {
  1145. X          last_read= len!=CP_BUFF;
  1146. X          bufptr=buffer;
  1147. X          *(buffer+len)='\0';
  1148. X        }
  1149. X    }
  1150. X}
  1151. X
  1152. Xsavedl()
  1153. X{
  1154. X  if( update() )
  1155. X    return 1;
  1156. X
  1157. X  if( strcmp(dlpath,dldisk) )
  1158. X  {
  1159. X    if( copy(dlpath,dldisk) )
  1160. X      return 1;
  1161. X    DeleteFile(dlpath);
  1162. X    DeleteFile(tempdl);
  1163. X  }
  1164. X  return 0;
  1165. X}
  1166. X
  1167. Xloaddl()
  1168. X{
  1169. X  if( strcmp(dltemp,dlpath) )
  1170. X    if( copy(dlpath,dltemp) )
  1171. X      return 1;
  1172. X  return 0;
  1173. X}
  1174. X
  1175. Xnewdl()
  1176. X{
  1177. X  BPTR fh;
  1178. X
  1179. X  putstr("Are you sure? ");
  1180. X  Read(confh,buffer,LINELEN);
  1181. X
  1182. X  if( *buffer=='y' )
  1183. X  {
  1184. X    if( fh=Open(dlpath,(long)MODE_NEWFILE) )
  1185. X    {
  1186. X      Close(fh);
  1187. X      return 0;
  1188. X    }
  1189. X    return 1;
  1190. X  }
  1191. X  return 0;
  1192. X}
  1193. X
  1194. Xcopy(src,dest)
  1195. X  char *src,*dest;
  1196. X{
  1197. X  BPTR sfh,dfh;
  1198. X  char *buffer;
  1199. X  int  len;
  1200. X
  1201. X  if((sfh=Open(src,(long)MODE_OLDFILE))==0)
  1202. X    return 1;
  1203. X
  1204. X  if((dfh=Open(dest,(long)MODE_NEWFILE))==0)
  1205. X  {
  1206. X    Close(sfh);
  1207. X    return 2;
  1208. X  }
  1209. X  if( (buffer=(char *)AllocMem(CP_BUFF,0L))==0)
  1210. X  {
  1211. X    Close(sfh);
  1212. X    Close(dfh);
  1213. X    putstr(outofmem);
  1214. X    return 3;
  1215. X  }
  1216. X
  1217. X  do
  1218. X  {
  1219. X    len=Read(sfh,buffer,CP_BUFF);
  1220. X    Write(dfh,buffer,(long)len);
  1221. X  }
  1222. X  while( len!=0 );
  1223. X
  1224. X  FreeMem(buffer,CP_BUFF);
  1225. X
  1226. X  Close(sfh);
  1227. X  Close(dfh);
  1228. X  return 0;
  1229. X}
  1230. X
  1231. X
  1232. X
  1233. X
  1234. END_OF_FILE
  1235. if test 21252 -ne `wc -c <'fd2src/fd2.c'`; then
  1236.     echo shar: \"'fd2src/fd2.c'\" unpacked with wrong size!
  1237. fi
  1238. # end of 'fd2src/fd2.c'
  1239. fi
  1240. if test -f 'fd3src/fd3.c' -a "${1}" != "-c" ; then 
  1241.   echo shar: Will not clobber existing file \"'fd3src/fd3.c'\"
  1242. else
  1243. echo shar: Extracting \"'fd3src/fd3.c'\" \(22393 characters\)
  1244. sed "s/^X//" >'fd3src/fd3.c' <<'END_OF_FILE'
  1245. X
  1246. X/*                            FindDisk3.3
  1247. X
  1248. X     Author      : Ross MacGregor
  1249. X     Date        : 10/04/88
  1250. X     Last Update : 23 Apr 91
  1251. X     Comments    : This is a public domain program.
  1252. X
  1253. X
  1254. X     DiskList stored in compacted form:
  1255. X
  1256. X     below: { unskrunched } => { skrunched }
  1257. X            [] is a byte of memory
  1258. X
  1259. X     * compacts strings of spaces
  1260. X         { [$20] [$20] [$20] [$20] [$20] } => { [SKRUNCHAR] [SKRUNOFFS 5] }
  1261. X         { [$20] [$20] } => { [$20] [$20] }
  1262. X
  1263. X     * the STARTSTR is compacted
  1264. X         { STARTSTR } => { [STARTCHAR] }
  1265. X
  1266. X*/
  1267. X
  1268. X#include <functions.h>
  1269. X#include <string.h>
  1270. X
  1271. X#include <exec/types.h>
  1272. X#include <exec/nodes.h>
  1273. X#include <exec/lists.h>
  1274. X#include <exec/libraries.h>
  1275. X#include <exec/ports.h>
  1276. X#include <exec/interrupts.h>
  1277. X#include <exec/io.h>
  1278. X#include <exec/memory.h>
  1279. X#include <libraries/dos.h>
  1280. X#include <libraries/dosextens.h>
  1281. X#include <libraries/filehandler.h>
  1282. X
  1283. X
  1284. X#define DISP_LINES 23
  1285. X
  1286. X#define CP_BUFF 10000L    /* Buffer size for the file copy function */
  1287. X
  1288. X/* This indicates the start line of a dir listing, and
  1289. X   it MUST have the name of the disk on the same line.  */
  1290. X
  1291. X#define STARTSTR  "Directory of "
  1292. X
  1293. X/* Special character used to compact the spaces in DiskList */
  1294. X#define SKRUNCHAR 1
  1295. X#define SKRUNOFFS 10
  1296. X
  1297. X/* Special characters used to replace the STARTSTR & XnSTR in DiskList  */
  1298. X#define STARTCHAR  2
  1299. X
  1300. X/* Lines in the stored dir listing array */
  1301. X#define NUMLINES 25
  1302. X
  1303. X/* Max length of the lines read in */
  1304. X#define LINELEN  170L
  1305. X#define MAXBUF   169L
  1306. X
  1307. X#define MAXPATHLEN 80
  1308. X
  1309. X/*--------------------- Global Variables ------------------------*/
  1310. X
  1311. XBPTR fdl, ftmp;
  1312. XBPTR confh;
  1313. X
  1314. Xchar *tempdl="ram:TempDL";
  1315. X
  1316. Xchar *dltemp="ram:DiskList";
  1317. Xchar *dldisk="FindDisk:DiskList";
  1318. Xchar *sdir_pat="df0:";
  1319. X
  1320. Xchar *outofmem="Out of Memory.";
  1321. Xchar *cutoff=" - - (no more lines available) - - \n";
  1322. X
  1323. Xchar dlpath[MAXPATHLEN+1];
  1324. Xchar buffer[LINELEN];
  1325. X
  1326. X/* finddisk uses this */
  1327. Xchar dirlist[NUMLINES][LINELEN];
  1328. X
  1329. Xint con_print_line, last_startchar, disp_list;
  1330. Xchar *errorstr;
  1331. Xchar *nullstr="";
  1332. X
  1333. X/* function error indicator */
  1334. Xint fcnerr;
  1335. X
  1336. X/* global main arguments */
  1337. Xint glargc;
  1338. Xchar **glargv;
  1339. X
  1340. Xextern char strbuf[];
  1341. Xextern int  subdir, shdsp;
  1342. X
  1343. X/*------------ dynamic structure for coping DL to memory -------------*/
  1344. X
  1345. X/* Blocks of memory for storing the disklist */
  1346. X#define BLKSIZE 4096L
  1347. X
  1348. Xstruct mem_block
  1349. X{
  1350. X  char buffer[BLKSIZE+1];
  1351. X  struct mem_block *next;
  1352. X};
  1353. X
  1354. Xstruct mem_block *mem_blocks, *cur_mem_block;
  1355. Xchar *mem_block_ptr;
  1356. Xint chrcount;
  1357. Xvoid init_bufblks(), free_bufblks();
  1358. Xint  write_bufblks(BPTR fd);
  1359. X
  1360. X/*------------ dynamic structure for listing the volume names --------*/
  1361. X/*                   used in recursive do_ls call also                */
  1362. X
  1363. Xstruct disk
  1364. X{
  1365. X  char name[LINELEN];
  1366. X  struct disk *next;
  1367. X};
  1368. Xstruct disk *firstdisk,*diskptr;
  1369. X
  1370. X#define INIT_DISKNAMES firstdisk=diskptr=NULL
  1371. X#define FREE_DISKNAMES free_disknames()
  1372. X
  1373. Xvoid free_disknames();
  1374. X
  1375. X/*----------------------------------------------------------------------*/
  1376. X
  1377. Xchar *mystrstr(), *strtoupper(), *getstr();
  1378. X
  1379. Xchar *skrunch(), *getenv(), *firstchar();
  1380. Xvoid tocon(), unskrunch(), get_dlpath();
  1381. XBPTR opendl(), opentmp();
  1382. X
  1383. Xchar *strchr(), *malloc();
  1384. X
  1385. Xint update(), remove(), loaddl(), savedl(), sdir(), newdl();
  1386. X
  1387. Xvoid finddisk_free(), update_free(), remove_free(), ls_free();
  1388. X
  1389. Xchar *getenv(fullpath,var)
  1390. X  char *fullpath, *var;
  1391. X{
  1392. X  BPTR lock;
  1393. X  BPTR fh;
  1394. X  char *buffer;
  1395. X  int  len;
  1396. X
  1397. X  if( lock=Lock(fullpath,(long)ACCESS_READ) )
  1398. X  {
  1399. X    UnLock(lock);
  1400. X    if( !(fh=Open(fullpath,(long)MODE_OLDFILE)) )
  1401. X      return var;
  1402. X    if( !(buffer=(char *)malloc(MAXPATHLEN+1)) )
  1403. X    {
  1404. X      errorstr=outofmem;
  1405. X      Close(fh);
  1406. X      return var;
  1407. X    }
  1408. X    len=Read(fh,buffer,(long)MAXPATHLEN);
  1409. X    Close(fh);
  1410. X    *(buffer+len)='\0';
  1411. X    return buffer;
  1412. X  }
  1413. X  return var;
  1414. X}
  1415. X
  1416. Xtmpsize()
  1417. X{
  1418. X  int size;
  1419. X  if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
  1420. X  {
  1421. X    errorstr=nullstr;
  1422. X    return 0;
  1423. X  }
  1424. X  size=Read(ftmp,buffer,(long)MAXBUF);
  1425. X  Close(ftmp);
  1426. X  return size;
  1427. X}
  1428. X
  1429. X#define finddisk_cleanup(x) { finddisk_free(); return x; }
  1430. Xfinddisk()
  1431. X{
  1432. X  int thisone=0, line=0;
  1433. X  int i;
  1434. X
  1435. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  1436. X    return 1;
  1437. X
  1438. X  confh=0;
  1439. X
  1440. X  /* Converts non-case sensitive keywords to upper case */
  1441. X  for(i=1; i<glargc; i++)
  1442. X    if( *glargv[i]!='!' )
  1443. X      strtoupper(glargv[i]);
  1444. X
  1445. X  con_print_line=0;
  1446. X  disp_list=1;
  1447. X
  1448. X  /* get line of DiskList */
  1449. X  while( getstr(buffer,fdl)!=NULL && disp_list)
  1450. X  {
  1451. X    /* first checks for a startchar of a dirlist */
  1452. X    if( strchr(buffer,(char)STARTCHAR) )
  1453. X    {
  1454. X       if( thisone )
  1455. X       {
  1456. X         last_startchar=con_print_line;
  1457. X         if( printdir(&line) )
  1458. X           finddisk_cleanup(1);
  1459. X         thisone=0;
  1460. X       }
  1461. X
  1462. X       line=1;
  1463. X    }
  1464. X
  1465. X
  1466. X    if( line )
  1467. X    {
  1468. X
  1469. X       /* Copies the line in buffer to the stored dirlist */
  1470. X       strcpy(dirlist[line-1],buffer);
  1471. X
  1472. X       if( ++line > NUMLINES )
  1473. X         line--;
  1474. X
  1475. X       /* Checks for given keywords */
  1476. X       if( thisone==0 )
  1477. X         thisone=chkmatch(buffer);
  1478. X    }/* if(line) */
  1479. X
  1480. X  } /* while( get next buffer) */
  1481. X  if( fcnerr )
  1482. X  {
  1483. X    fcnerr=0;
  1484. X    finddisk_cleanup(2);
  1485. X  }
  1486. X
  1487. X  if( !disp_list )
  1488. X    while( getstr(buffer,fdl)!=NULL);
  1489. X  else
  1490. X  {
  1491. X    if( thisone )
  1492. X      if( printdir(&line) )
  1493. X        finddisk_cleanup(3);
  1494. X
  1495. X    if( con_print_line )
  1496. X    {
  1497. X      fputstr("[ Quit ]",confh);
  1498. X      Read(confh,buffer,5L);
  1499. X    }
  1500. X  }
  1501. X
  1502. X  finddisk_cleanup(0)
  1503. X}
  1504. X
  1505. Xvoid finddisk_free()
  1506. X{
  1507. X  Close(fdl);
  1508. X  if( confh )
  1509. X    Close(confh);
  1510. X}
  1511. X
  1512. X
  1513. Xprintdir(line)
  1514. X  int *line;
  1515. X{
  1516. X  int i;
  1517. X
  1518. X  if( !confh )
  1519. X    if( (confh=Open("CON:0/0/640/200/FindDisk3.3",(long)MODE_OLDFILE))==0)
  1520. X    {
  1521. X       errorstr=(" Could not open display window.");
  1522. X       return 1;
  1523. X    }
  1524. X
  1525. X  /* print the directory */
  1526. X  (*line)--;
  1527. X  for(i=0; i<*line; i++)
  1528. X    if( shdsp && i )
  1529. X    {
  1530. X      if( chkmatch(dirlist[i]) )
  1531. X        unskrunch(dirlist[i]);
  1532. X    }
  1533. X    else
  1534. X      unskrunch(dirlist[i]);
  1535. X
  1536. X  /* if at the end of the dirlist array- prints 'cut off' */
  1537. X  if( *line==NUMLINES-1 )
  1538. X    tocon(cutoff);
  1539. X
  1540. X  return 0;
  1541. X}
  1542. X
  1543. X
  1544. Xchkmatch(buffer)
  1545. X  char *buffer;
  1546. X{
  1547. X  int i, kase;
  1548. X  char *p;
  1549. X
  1550. X  for(i=1; i<glargc; i++)
  1551. X  {
  1552. X    if( *glargv[i]=='!' )
  1553. X    {
  1554. X      p=glargv[i]+1;
  1555. X      kase=1;
  1556. X    }
  1557. X    else
  1558. X    {
  1559. X      p=glargv[i];
  1560. X      kase=0;
  1561. X    }
  1562. X    if( !mystrstr(buffer,p,kase) )
  1563. X      return 0;
  1564. X  }
  1565. X  return 1;
  1566. X}
  1567. X
  1568. X
  1569. Xvoid tocon(s)
  1570. X  char *s;
  1571. X{
  1572. X  char inp[6];
  1573. X
  1574. X  if( ++con_print_line>=DISP_LINES )
  1575. X  {
  1576. X    fputstr("[ More... ]",confh);
  1577. X    Read(confh,inp,5L);
  1578. X    inp[5]='\0';
  1579. X    if( strchr(inp,'q') )
  1580. X      disp_list=0;
  1581. X    fputstr("\013\033[K\015",confh);
  1582. X    con_print_line-=last_startchar;
  1583. X  }
  1584. X  fputstr(s,confh);
  1585. X}
  1586. X
  1587. X
  1588. X#define update_cleanup(x)  { update_free(); return x; }
  1589. X
  1590. Xupdate()
  1591. X{
  1592. X  int  i;
  1593. X
  1594. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  1595. X    return 1;
  1596. X
  1597. X  if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
  1598. X  {
  1599. X    Close(fdl);
  1600. X    return 0;
  1601. X  }
  1602. X
  1603. X  INIT_DISKNAMES;
  1604. X  init_bufblks();
  1605. X
  1606. X  /* finds the disks names in TempDL */
  1607. X  while( getstr(buffer,ftmp) !=NULL )
  1608. X  {
  1609. X      if( mystrstr(buffer,STARTSTR,1) )
  1610. X      {
  1611. X         skrunch(buffer);
  1612. X         if( storename(buffer) )
  1613. X           update_cleanup(3)
  1614. X      }
  1615. X  }
  1616. X  if( fcnerr )
  1617. X  {
  1618. X    fcnerr=0;
  1619. X    update_cleanup(10)
  1620. X  }
  1621. X
  1622. X  if( storedl() )
  1623. X    update_cleanup(4)
  1624. X
  1625. X  Seek(ftmp,0L,(long)OFFSET_BEGINNING);
  1626. X
  1627. X  /* store TempDL in memory */
  1628. X  while( getstr(buffer,ftmp) !=NULL )
  1629. X    if( store( skrunch(buffer) ) )
  1630. X      update_cleanup(5)
  1631. X  if( fcnerr )
  1632. X  {
  1633. X    fcnerr=0;
  1634. X    update_cleanup(6);
  1635. X  }
  1636. X
  1637. X  Close(fdl);
  1638. X  if( !(fdl=opendl((long)MODE_NEWFILE)) )
  1639. X  {
  1640. X    Close(ftmp);
  1641. X    FREE_DISKNAMES;
  1642. X    free_bufblks();
  1643. X    return 6;
  1644. X  }
  1645. X
  1646. X  /* write the in memory disklist to the one in ram: */
  1647. X  if( write_bufblks(fdl) )
  1648. X    update_cleanup(8)
  1649. X
  1650. X  Close(ftmp);
  1651. X  if( !(ftmp=opentmp((long)MODE_NEWFILE)) )
  1652. X    update_cleanup(7)
  1653. X
  1654. X  update_free();
  1655. X  return 0;
  1656. X}
  1657. X
  1658. Xvoid update_free()
  1659. X{
  1660. X  Close(fdl);
  1661. X  Close(ftmp);
  1662. X  FREE_DISKNAMES;
  1663. X  free_bufblks();
  1664. X}
  1665. X
  1666. X
  1667. X#define remove_cleanup(x)  { remove_free(); return x; }
  1668. X
  1669. Xremove()
  1670. X{
  1671. X  int i;
  1672. X  char *p;
  1673. X
  1674. X  if( *(p=firstchar(strbuf))=='\0' )
  1675. X     return 1;
  1676. X
  1677. X  if( !(fdl=opendl((long)MODE_OLDFILE)) )
  1678. X    return 2;
  1679. X
  1680. X  INIT_DISKNAMES;
  1681. X  init_bufblks();
  1682. X
  1683. X  /* finds the disk name in DiskList */
  1684. X  while( getstr(buffer,fdl) !=NULL )
  1685. X  {
  1686. X      if( mystrstr(buffer,p,1) )
  1687. X      {
  1688. X         if( storename(buffer) )
  1689. X           remove_cleanup(3)
  1690. X      }
  1691. X  }
  1692. X  if( fcnerr )
  1693. X  {
  1694. X    fcnerr=0;
  1695. X    remove_cleanup(4);
  1696. X  }
  1697. X
  1698. X  Seek(fdl,0L,(long)OFFSET_BEGINNING);
  1699. X
  1700. X  if( storedl() )
  1701. X    remove_cleanup(4)
  1702. X
  1703. X  Close(fdl);
  1704. X  if( !(fdl=opendl((long)MODE_NEWFILE)) )
  1705. X  {
  1706. X    FREE_DISKNAMES;
  1707. X    free_bufblks();
  1708. X    return 5;
  1709. X  }
  1710. X
  1711. X  /* write the in memory disklist to the one in ram: */
  1712. X  if( write_bufblks(fdl) )
  1713. X      remove_cleanup(6)
  1714. X
  1715. X  remove_free();
  1716. X  return 0;
  1717. X}
  1718. X
  1719. Xvoid remove_free()
  1720. X{
  1721. X  Close(fdl);
  1722. X  FREE_DISKNAMES;
  1723. X  free_bufblks();
  1724. X}
  1725. X
  1726. X
  1727. X/* loads the DiskList into memory but leaves out the directories in the
  1728. X   diskname list, pointed to by firstdisk */
  1729. Xstoredl()
  1730. X{
  1731. X  int storeit=1;  /* saving this directory */
  1732. X
  1733. X  /* doesn't store directories that are in the temp file */
  1734. X  while( getstr(buffer,fdl) !=NULL )
  1735. X  {
  1736. X      if( strchr(buffer,(char)STARTCHAR) )
  1737. X      {
  1738. X         storeit=1;
  1739. X         diskptr=firstdisk;
  1740. X         while(diskptr)
  1741. X         {
  1742. X           if( mystrstr(buffer,diskptr->name,1) )
  1743. X           {
  1744. X             storeit=0;
  1745. X             break;
  1746. X           }
  1747. X           diskptr=diskptr->next;
  1748. X         }
  1749. X      }
  1750. X
  1751. X      if(storeit)
  1752. X       if( store(buffer) )
  1753. X         return 1;
  1754. X  }
  1755. X
  1756. X  if( fcnerr )
  1757. X  {
  1758. X    fcnerr=0;
  1759. X    return 2;
  1760. X  }
  1761. X  return 0;
  1762. X}
  1763. X
  1764. X/* must be used in the WHILE( GETSTR()!=NULL) fashion */
  1765. Xchar *getstr(line,f)
  1766. X  char *line;
  1767. X  BPTR f;
  1768. X{
  1769. X  static char *buffer, *bufptr;
  1770. X  static int  last_read;
  1771. X  int len, n=MAXBUF;
  1772. X  char temp, *p, empty='\0';
  1773. X
  1774. X  if( !buffer )
  1775. X  {
  1776. X    if( (buffer=(char *)AllocMem((long)CP_BUFF+1,0L))==0)
  1777. X    {
  1778. X       errorstr=outofmem;
  1779. X       fcnerr=1;
  1780. X       return (char *)0;
  1781. X    }
  1782. X    bufptr=∅
  1783. X  }
  1784. X
  1785. X  while(1)
  1786. X    if( p=strchr(bufptr,'\n') )
  1787. X    {
  1788. X      temp=*(++p);
  1789. X      *p='\0';
  1790. X      strncpy(line,bufptr,n);
  1791. X      *p=temp;
  1792. X      bufptr=p;
  1793. X      return line;
  1794. X    }
  1795. X    else
  1796. X    {
  1797. X      strncpy(line,bufptr,n);
  1798. X      len=strlen(line);
  1799. X      n-=len;
  1800. X      line+=len;
  1801. X
  1802. X      if( last_read )
  1803. X      {
  1804. X        FreeMem(buffer,CP_BUFF+1);
  1805. X        buffer=0;
  1806. X        last_read=0;
  1807. X        return (char *)0;
  1808. X      }
  1809. X      else
  1810. X        if( (len=Read(f,buffer,CP_BUFF)) <1 )
  1811. X          last_read=1;
  1812. X        else
  1813. X        {
  1814. X          last_read= len!=CP_BUFF;
  1815. X          bufptr=buffer;
  1816. X          *(buffer+len)='\0';
  1817. X        }
  1818. X    }
  1819. X}
  1820. X
  1821. X
  1822. X/* Saves the name of a disk in a linked list structure */
  1823. Xstorename(buffer)
  1824. X char *buffer;
  1825. X{
  1826. X  if( diskptr==NULL )
  1827. X  {
  1828. X    if( (firstdisk=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
  1829. X    {
  1830. X      errorstr=outofmem;
  1831. X      return 1;
  1832. X    }
  1833. X    diskptr=firstdisk;
  1834. X    strcpy(diskptr->name,buffer);
  1835. X    diskptr->next=NULL;
  1836. X  }
  1837. X  else
  1838. X  {
  1839. X    if( (diskptr->next=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
  1840. X    {
  1841. X      errorstr=outofmem;
  1842. X      return 2;
  1843. X    }
  1844. X    diskptr=diskptr->next;
  1845. X    strcpy(diskptr->name,buffer);
  1846. X    diskptr->next=NULL;
  1847. X  }
  1848. X
  1849. X  return 0;
  1850. X}
  1851. X
  1852. Xvoid free_disknames()
  1853. X{
  1854. X  struct disk *p;
  1855. X
  1856. X  while(firstdisk)
  1857. X  {
  1858. X    p=firstdisk->next;
  1859. X    free(firstdisk);
  1860. X    firstdisk=p;
  1861. X  }
  1862. X}
  1863. X
  1864. X
  1865. X/* prints line to confh unskrunched */
  1866. X/* format  [BYTE]=>   [SKRUNCHAR] [# of spaces ]   */
  1867. X
  1868. Xvoid unskrunch(line)
  1869. X  char *line;
  1870. X{
  1871. X  char output[LINELEN], *p;
  1872. X  int i;
  1873. X
  1874. X  p=output;
  1875. X  while(*line)
  1876. X  {
  1877. X    switch((int)*line)
  1878. X    {
  1879. X      case SKRUNCHAR : line++;
  1880. X                       for(i=SKRUNOFFS; i<(int)*line; i++)
  1881. X                         *(p++)=' ';
  1882. X                       break;
  1883. X
  1884. X      case STARTCHAR : strcpy(p,STARTSTR);
  1885. X                       p+=strlen(STARTSTR);
  1886. X                       break;
  1887. X
  1888. X      default : *(p++)=*line;
  1889. X    }
  1890. X
  1891. X    line++;
  1892. X  }
  1893. X  *p='\0';
  1894. X  tocon(output);
  1895. X}
  1896. X
  1897. X
  1898. Xchar *skrunch(line)
  1899. X  char *line;
  1900. X{
  1901. X  char skbuf[LINELEN],*p;
  1902. X  int  spaces=0;
  1903. X
  1904. X  /* first tokenizes the STARTSTR/XnSTR if in line */
  1905. X
  1906. X  tokenize(line,STARTSTR,STARTCHAR);
  1907. X
  1908. X  /* this is the compaction of >2 spaces */
  1909. X  p=skbuf;
  1910. X  while( *line )
  1911. X  {
  1912. X    if( *line==' ' )
  1913. X      spaces++;
  1914. X    else
  1915. X    {
  1916. X      if( spaces )
  1917. X        if( spaces>2 )
  1918. X        {
  1919. X          *(p++)=(char)SKRUNCHAR;
  1920. X          *(p++)=(char)(spaces+SKRUNOFFS);
  1921. X          spaces=0;
  1922. X        }
  1923. X        else
  1924. X        {
  1925. X          *(p++)=' ';
  1926. X          if( spaces>1 ) *(p++)=' ';
  1927. X          spaces=0;
  1928. X        }
  1929. X
  1930. X      *p=*line;
  1931. X      p++;
  1932. X    }
  1933. X    line++;
  1934. X  }
  1935. X  *p='\0';
  1936. X  strcpy(buffer,skbuf);
  1937. X  return buffer;
  1938. X}
  1939. X
  1940. X
  1941. X/* will tokenize first occurance of STR in LINE */
  1942. Xtokenize(line,str,chr)
  1943. X  char *line,*str;
  1944. X  int  chr;
  1945. X{
  1946. X  char *p,*q;
  1947. X
  1948. X  if( p=mystrstr(line,str,1) )
  1949. X  {
  1950. X    q=p+strlen(str);
  1951. X    *p=(char)chr;
  1952. X    strcpy(p+1,q);
  1953. X    return 1;
  1954. X  }
  1955. X  return 0;
  1956. X}
  1957. X
  1958. X/* stores line to memory */
  1959. Xstore(buffer)
  1960. X  char *buffer;
  1961. X{
  1962. X  struct mem_block *p;
  1963. X  int i;
  1964. X
  1965. X  i=strlen(buffer);
  1966. X  chrcount+=i;
  1967. X
  1968. X  if( chrcount>=BLKSIZE )
  1969. X  {
  1970. X    if( mem_block_ptr )
  1971. X      *mem_block_ptr='\0';
  1972. X    chrcount=i;
  1973. X
  1974. X    if( (p=(struct mem_block *)malloc(sizeof(struct mem_block)) )==NULL)
  1975. X    {
  1976. X       errorstr=outofmem;
  1977. X       return 2;
  1978. X    }
  1979. X
  1980. X    p->next=NULL;
  1981. X
  1982. X    if( mem_blocks )
  1983. X      cur_mem_block->next=p;
  1984. X    else
  1985. X      mem_blocks=p;
  1986. X    cur_mem_block=p;
  1987. X
  1988. X    mem_block_ptr=cur_mem_block->buffer;
  1989. X  }
  1990. X
  1991. X  strcpy(mem_block_ptr,buffer);
  1992. X  mem_block_ptr+=i;
  1993. X
  1994. X  return 0;
  1995. X}
  1996. X
  1997. Xwrite_bufblks(BPTR fd)
  1998. X{
  1999. X  struct mem_block *p;
  2000. X
  2001. X  p=mem_blocks;
  2002. X  while(p)
  2003. X  {
  2004. X    if( fputstr(p->buffer,fd) )
  2005. X      return 1;
  2006. X    p=p->next;
  2007. X  }
  2008. X
  2009. X  return 0;
  2010. X}
  2011. X
  2012. X
  2013. Xvoid init_bufblks()
  2014. X{
  2015. X  mem_block_ptr=NULL;
  2016. X  chrcount=BLKSIZE+1;
  2017. X  cur_mem_block=NULL;
  2018. X  mem_blocks=NULL;
  2019. X}
  2020. X
  2021. Xvoid free_bufblks()
  2022. X{
  2023. X  struct mem_block *p,*next;
  2024. X
  2025. X  p=mem_blocks;
  2026. X  while(p)
  2027. X  {
  2028. X    next=p->next;
  2029. X    free(p);
  2030. X    p=next;
  2031. X  }
  2032. X}
  2033. X
  2034. X
  2035. Xvoid get_dlpath()
  2036. X{
  2037. X  BPTR lock;
  2038. X
  2039. X  dlpath[MAXPATHLEN]='\0';
  2040. X
  2041. X  if( lock=Lock(dltemp,(long)ACCESS_READ) )
  2042. X  {
  2043. X    strncpy(dlpath,dltemp,MAXPATHLEN);
  2044. X    UnLock(lock);
  2045. X  }
  2046. X  else
  2047. X    strncpy(dlpath,dldisk,MAXPATHLEN);
  2048. X}
  2049. X
  2050. XBPTR opendl(mode)
  2051. X  long mode;
  2052. X{
  2053. X  BPTR fdl;
  2054. X
  2055. X  if( (fdl=Open(dlpath,mode))==NULL)
  2056. X  {
  2057. X    errorstr="Can't open DiskList.";
  2058. X    return 0;
  2059. X  }
  2060. X  return fdl;
  2061. X}
  2062. X
  2063. X
  2064. X#define MODE_APPEND 1000L
  2065. X
  2066. XBPTR opentmp(mode)
  2067. X  long mode;
  2068. X{
  2069. X  BPTR ftmp;
  2070. X  BPTR lock;
  2071. X  int    seek=0;
  2072. X
  2073. X  if( mode==MODE_APPEND)
  2074. X  {
  2075. X    if( lock=Lock(tempdl,(long)ACCESS_READ) )
  2076. X    {
  2077. X      UnLock(lock);
  2078. X      mode=(long)MODE_OLDFILE;
  2079. X      seek=1;
  2080. X    }
  2081. X    else
  2082. X      mode=(long)MODE_NEWFILE;
  2083. X  }
  2084. X
  2085. X  if( (ftmp=Open(tempdl,mode))==NULL)
  2086. X  {
  2087. X    errorstr=" Can't open TempDL.";
  2088. X    return 0;
  2089. X  }
  2090. X
  2091. X  if( seek )
  2092. X    Seek(ftmp,0L,(long)OFFSET_END);
  2093. X
  2094. X  return ftmp;
  2095. X}
  2096. X
  2097. X
  2098. Xsdir()
  2099. X{
  2100. X  char *p;
  2101. X
  2102. X  if( *(p=firstchar(strbuf))=='\0' )
  2103. X    p=sdir_pat;
  2104. X
  2105. X  if( !(ftmp=opentmp(MODE_APPEND)) )
  2106. X    return 1;
  2107. X
  2108. X  if( do_ls(p,ftmp,subdir) )
  2109. X  {
  2110. X    Close(ftmp);
  2111. X    return 2;
  2112. X  }
  2113. X  Close(ftmp);
  2114. X  return 0;
  2115. X}
  2116. X
  2117. X
  2118. X#define ls_cleanup(x) { ls_free(lock,f_info); return x; }
  2119. X
  2120. Xdo_ls(pat,fh,recur)
  2121. X  char *pat;
  2122. X  BPTR fh;
  2123. X  int recur;
  2124. X{
  2125. X  BPTR lock=NULL;
  2126. X  struct FileInfoBlock *f_info;
  2127. X
  2128. X  char *s, *tempstr;
  2129. X  int  slen, isadir, col, patchg=0, firstrun=1;
  2130. X  char *spaces1, *spaces2;
  2131. X  struct disk *nextdir;
  2132. X  char basename[80], tempname[80];
  2133. X
  2134. X
  2135. X  /* strings of 18 & 36 spaces for formatting output */
  2136. X  /*       012345678901234567                        */
  2137. X  spaces1="                  ";
  2138. X  /*       0123456789012345678901234567890123456     */
  2139. X  spaces2="                                     ";
  2140. X
  2141. X  INIT_DISKNAMES;
  2142. X  nextdir=NULL;
  2143. X
  2144. X  strcpy(tempname,"/");
  2145. X  tempstr=tempname+1;
  2146. X
  2147. X  if((f_info=(struct FileInfoBlock *)
  2148. X     AllocMem((long)sizeof(struct FileInfoBlock),0L))==0)
  2149. X  {
  2150. X    errorstr=outofmem;
  2151. X    FREE_DISKNAMES;
  2152. X    return 1;
  2153. X  }
  2154. X
  2155. X  do
  2156. X  {
  2157. X    if( firstdisk )
  2158. X    {
  2159. X      while( nextdir && *(nextdir->name)=='/' )
  2160. X      {
  2161. X        strncpy(basename,(nextdir->name)+1,78);
  2162. X        strncpy(basename+strlen(basename),"/",2);
  2163. X        nextdir=nextdir->next;
  2164. X        if( !nextdir )
  2165. X          ls_cleanup(0)
  2166. X      }
  2167. X      strncpy(tempname+1,basename,78);
  2168. X      slen=strlen(tempname);
  2169. X      strncpy(tempname+slen,nextdir->name,79-slen);
  2170. X      if( storename(tempname) )
  2171. X        ls_cleanup(1);
  2172. X      pat=tempname+1;
  2173. X    }
  2174. X
  2175. X    do
  2176. X    {
  2177. X      if( firstrun )
  2178. X      {
  2179. X        if(patchg==1)
  2180. X        {
  2181. X          patchg=2;
  2182. X          strncpy(tempstr,f_info->fib_FileName,78);
  2183. X          slen=strlen(tempstr);
  2184. X          tempstr[slen]=':';
  2185. X          strncpy(tempstr+slen+1,s+4,78-slen);
  2186. X          pat=tempstr;
  2187. X        }
  2188. X        else if( strchr(pat,':')<strchr(pat,'\0')-1 )
  2189. X        {
  2190. X          patchg=2;
  2191. X          if( !(strncmp(pat,"df0:",4) && strncmp(pat,"df1:",4)) )
  2192. X          {
  2193. X            patchg=1;
  2194. X            strncpy(tempstr,pat,4);
  2195. X            *(tempstr+4)='\0';
  2196. X            s=pat;
  2197. X            pat=tempstr;
  2198. X          }
  2199. X        }
  2200. X      }
  2201. X
  2202. X      if((lock=Lock(pat,(long)ACCESS_READ))==0)
  2203. X        ls_cleanup(2)
  2204. X
  2205. X      if((Examine(lock,f_info))==0)
  2206. X        ls_cleanup(3)
  2207. X    }
  2208. X    while( patchg==1 );
  2209. X    firstrun=0;
  2210. X
  2211. X    if( fputstr(STARTSTR,fh) )
  2212. X      ls_cleanup(4)
  2213. X    if( firstdisk )
  2214. X    {
  2215. X      fputstr(tempname+1,fh);
  2216. X      fputstr ("\n",fh);
  2217. X    }
  2218. X    else
  2219. X    {
  2220. X      if( patchg )
  2221. X      {
  2222. X        patchg=0;
  2223. X        if( fputstr(pat,fh) )
  2224. X          ls_cleanup(5)
  2225. X        fputstr ("\n",fh);
  2226. X        strncpy(basename,pat,79L);
  2227. X        slen=strlen(basename);
  2228. X        basename[slen++]='/';
  2229. X        basename[slen]='\0';
  2230. X
  2231. X      }
  2232. X      else
  2233. X      {
  2234. X        if( fputstr(f_info->fib_FileName,fh) )
  2235. X          ls_cleanup(6)
  2236. X        fputstr (":\n",fh);
  2237. X        strncpy(basename,f_info->fib_FileName,78);
  2238. X        slen=strlen(basename);
  2239. X        basename[slen++]=':';
  2240. X        basename[slen]='\0';
  2241. X      }
  2242. X    }
  2243. X    col=0;
  2244. X
  2245. X    while( (ExNext(lock,f_info))!=0)
  2246. X    {
  2247. X      s=f_info->fib_FileName;
  2248. X      slen=strlen(s);
  2249. X      isadir= (f_info->fib_DirEntryType>0);
  2250. X
  2251. X      if((col == 3) && slen >18) {
  2252. X           fputstr("\n",fh);
  2253. X           col = 0;
  2254. X      }
  2255. X
  2256. X      if (isadir)
  2257. X        fputstr ("\033[33m ",fh);
  2258. X      else
  2259. X        fputstr (" ",fh);
  2260. X
  2261. X      if (slen >18) {
  2262. X         if( fputstr(s,fh) )
  2263. X           ls_cleanup(7)
  2264. X         col += 2;
  2265. X         if( fputstr(spaces2+slen,fh) )
  2266. X           ls_cleanup(8)
  2267. X      }
  2268. X      else {
  2269. X         if( fputstr(s,fh) )
  2270. X           ls_cleanup(9)
  2271. X         if( fputstr(spaces1+slen,fh) )
  2272. X           ls_cleanup(10)
  2273. X         col++;
  2274. X      }
  2275. X
  2276. X      if( isadir && recur )
  2277. X        if(storename(s))
  2278. X          ls_cleanup(1);
  2279. X
  2280. X      if (isadir)
  2281. X        fputstr("\033[0m",fh);
  2282. X
  2283. X      if (col > 3) {
  2284. X         fputstr("\n",fh);
  2285. X         col = 0;
  2286. X      }
  2287. X
  2288. X    }
  2289. X    fputstr("\n",fh);
  2290. X    if( col )
  2291. X      fputstr("\n",fh);
  2292. X
  2293. X    UnLock(lock);
  2294. X    lock=NULL;
  2295. X
  2296. X    if( nextdir )
  2297. X      nextdir=nextdir->next;
  2298. X    else
  2299. X      nextdir=firstdisk;
  2300. X  }
  2301. X  while( nextdir );
  2302. X
  2303. X  ls_free(lock,f_info);
  2304. X  return 0;
  2305. X}
  2306. X
  2307. Xvoid ls_free(lock,f_info)
  2308. X  BPTR lock;
  2309. X  struct FileInfoBlock *f_info;
  2310. X
  2311. X{
  2312. X  if( lock )
  2313. X    UnLock(lock);
  2314. X  FreeMem(f_info,(long)sizeof(struct FileInfoBlock));
  2315. X  FREE_DISKNAMES;
  2316. X}
  2317. X
  2318. X
  2319. Xfputstr(str,fh)
  2320. X  char *str;
  2321. X  BPTR fh;
  2322. X{
  2323. X   long len;
  2324. X   len=(long)strlen(str);
  2325. X   if( Write(fh,str,len)==len)
  2326. X     return 0;
  2327. X   return 1;
  2328. X}
  2329. X
  2330. X
  2331. Xsavedl()
  2332. X{
  2333. X  if( update() )
  2334. X    return 1;
  2335. X
  2336. X  if( strcmp(dlpath,dldisk) )
  2337. X  {
  2338. X    if( copy(dlpath,dldisk) )
  2339. X      return 2;
  2340. X    DeleteFile(dlpath);
  2341. X    strncpy(dlpath,dldisk,MAXPATHLEN);
  2342. X    DeleteFile(tempdl);
  2343. X  }
  2344. X  return 0;
  2345. X}
  2346. X
  2347. Xloaddl()
  2348. X{
  2349. X  if( strcmp(dltemp,dlpath) )
  2350. X    if( copy(dlpath,dltemp) )
  2351. X      return 1;
  2352. X  strncpy(dlpath,dltemp,MAXPATHLEN);
  2353. X  return 0;
  2354. X}
  2355. X
  2356. Xnewdl()
  2357. X{
  2358. X  BPTR fh;
  2359. X
  2360. X  if( fh=Open(dlpath,(long)MODE_NEWFILE) )
  2361. X  {
  2362. X    Close(fh);
  2363. X    return 0;
  2364. X  }
  2365. X  return 1;
  2366. X}
  2367. X
  2368. Xcopy(src,dest)
  2369. X  char *src,*dest;
  2370. X{
  2371. X  BPTR sfh,dfh;
  2372. X  char *buffer;
  2373. X  int  len;
  2374. X
  2375. X  if((sfh=Open(src,(long)MODE_OLDFILE))==0)
  2376. X    return 1;
  2377. X
  2378. X  if((dfh=Open(dest,(long)MODE_NEWFILE))==0)
  2379. X  {
  2380. X    Close(sfh);
  2381. X    return 2;
  2382. X  }
  2383. X  if( (buffer=(char *)AllocMem(CP_BUFF,0L))==0)
  2384. X  {
  2385. X    Close(sfh);
  2386. X    Close(dfh);
  2387. X    errorstr=outofmem;
  2388. X    return 3;
  2389. X  }
  2390. X
  2391. X  do
  2392. X  {
  2393. X    len=Read(sfh,buffer,CP_BUFF);
  2394. X    Write(dfh,buffer,(long)len);
  2395. X  }
  2396. X  while( len!=0 );
  2397. X
  2398. X  FreeMem(buffer,CP_BUFF);
  2399. X
  2400. X  Close(sfh);
  2401. X  Close(dfh);
  2402. X  return 0;
  2403. X}
  2404. X
  2405. Xchar *firstchar(s)
  2406. X  char *s;
  2407. X{
  2408. X  while(*s==' ')
  2409. X    s++;
  2410. X  return s;
  2411. X}
  2412. X
  2413. X/*   OK, this is not quite a true strstr() with case switch.
  2414. X     The sub string must be in upper case if kase=0 (?!sorry)    */
  2415. Xchar *mystrstr(string,sub,kase)
  2416. X  char *string,*sub;
  2417. X  int  kase;
  2418. X{
  2419. X  int length;
  2420. X  char copstr[LINELEN], *str;
  2421. X
  2422. X  /* string copied so it will not be converted to upper case */
  2423. X  strcpy(copstr,string);
  2424. X  str=copstr;
  2425. X
  2426. X  length=strlen(sub);
  2427. X
  2428. X  if( kase )
  2429. X    str=strchr(str,*sub);
  2430. X  else
  2431. X    str=strchr(strtoupper(str),*sub);
  2432. X
  2433. X  while( str )
  2434. X  {
  2435. X    if( strncmp(str,sub,length) )
  2436. X      str++;
  2437. X    else
  2438. X      return string+(str-copstr);
  2439. X
  2440. X    str=strchr(str,*sub);
  2441. X  }
  2442. X  return NULL;
  2443. X}
  2444. X
  2445. Xchar *strtoupper(s)
  2446. X  char *s;
  2447. X{
  2448. X    register char *p = s;
  2449. X
  2450. X    while(*p)
  2451. X    {
  2452. X       *p = toupper(*p);
  2453. X       p++;
  2454. X    }
  2455. X    return(s);
  2456. X}
  2457. X
  2458. X
  2459. X/* Following lifted from ...*/
  2460. X
  2461. X/* misc.c
  2462. X *      Misc. subroutines that like to live together...
  2463. X *
  2464. X * Phillip Lindsay (c) 1987 Commodore-Amiga - This code may be freely used
  2465. X * as long as the copyright notice is left intact.
  2466. X */
  2467. X
  2468. X/* btoc() takes a pointer to a BSTR and converts it to a
  2469. X * C string.
  2470. X */
  2471. Xchar *btoc(bstring)
  2472. XCPTR bstring;
  2473. X{
  2474. X register UBYTE len,count,*cstring=NULL;
  2475. X
  2476. X if (bstring) {
  2477. X    cstring = (UBYTE *) bstring;
  2478. X    len = cstring[0];
  2479. X    for(count=0;count < len;count++)
  2480. X        cstring[count] = cstring[count+1];
  2481. X
  2482. X    cstring[count] = '\0';
  2483. X }
  2484. X return((char *)cstring);
  2485. X}
  2486. X
  2487. X/*
  2488. X *  find a dos node in the system device list
  2489. X *
  2490. X */
  2491. Xstruct DeviceNode *finddosnode(lookfor)
  2492. Xchar    *lookfor;
  2493. X{
  2494. X    extern   struct DosLibrary *DOSBase;
  2495. X             struct RootNode   *rnode;
  2496. X             struct DosInfo    *dinfo;
  2497. X    register struct DeviceNode *dnode;
  2498. X    register char              *bname;
  2499. X    char                        name2[81];
  2500. X    BOOL                        found = FALSE;
  2501. X
  2502. X    rnode   = (struct RootNode *)  DOSBase->dl_Root;        /* find root node */
  2503. X    dinfo   = (struct DosInfo  *)  BADDR(rnode->rn_Info);   /* now dos info   */
  2504. X
  2505. X    Forbid();
  2506. X
  2507. X    for(dnode = (struct DeviceNode *) BADDR(dinfo->di_DevInfo); ( dnode ) ;
  2508. X      dnode = (struct DeviceNode *) BADDR(dnode->dn_Next))
  2509. X    {
  2510. X        bname = (char *) BADDR(dnode->dn_Name);
  2511. X        memmove(name2, bname, (ULONG)( bname[0] + 1 ) );
  2512. X
  2513. X        if ( !( strcmp( lookfor, strtoupper(btoc(name2)) ) ) ) {
  2514. X            found   =   TRUE;
  2515. X            break;
  2516. X        }
  2517. X
  2518. X    }
  2519. X
  2520. X    Permit();
  2521. X
  2522. X    return dnode;       /* NULL if not found */
  2523. X}
  2524. X
  2525. X/* end of misc.c */
  2526. X
  2527. END_OF_FILE
  2528. if test 22393 -ne `wc -c <'fd3src/fd3.c'`; then
  2529.     echo shar: \"'fd3src/fd3.c'\" unpacked with wrong size!
  2530. fi
  2531. # end of 'fd3src/fd3.c'
  2532. fi
  2533. echo shar: End of archive 3 \(of 3\).
  2534. cp /dev/null ark3isdone
  2535. MISSING=""
  2536. for I in 1 2 3 ; do
  2537.     if test ! -f ark${I}isdone ; then
  2538.     MISSING="${MISSING} ${I}"
  2539.     fi
  2540. done
  2541. if test "${MISSING}" = "" ; then
  2542.     echo You have unpacked all 3 archives.
  2543.     rm -f ark[1-9]isdone
  2544. else
  2545.     echo You still need to unpack the following archives:
  2546.     echo "        " ${MISSING}
  2547. fi
  2548. ##  End of shell archive.
  2549. exit 0
  2550. -- 
  2551. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  2552. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  2553. Post requests for sources, and general discussion to comp.sys.amiga.misc.
  2554.